<template>
	<view>
		<u-navbar :title="$t('系统消息')">
			<view slot="right" class="yidu" @click="yijian">
				<!-- #ifdef H5 || APP-PLUS-->
				<image src="../../static/image/qingchu.png" mode=""></image>
				<!-- #endif -->
				<!-- {{$t('一键已读')}} -->
			</view>
		</u-navbar>
		<view class="box">
			<view class="list n-flex-row n-justify-between" v-for="(item, idx) in list" :key="idx" @click="$.to('/pages/my/newsDetails?id=' + item.id)">
				<view class="left">
					<view class="tit">
						<view class="yuan" v-if="item.lock === 0"></view>
						<text>{{ item.title }}</text>
					</view>
					<view class="con">
						{{ item.jianjie }}
					</view>
				</view>

				<view class="time n-shrink-0">{{ item.create_time }}</view>
			</view>
		</view>
		<u-empty :text="$t('暂无通知')" :show="show" mode="message" margin-top="400"></u-empty>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				show: true
			};
		},
		onShow() {
		  if (!uni.getStorageSync("user")) {
			    uni.redirectTo({
			    	url:'../../pages/my/login'
			    })
			}
			this.getList();
		},
		methods: {
			getList() {
				this.$http({
					url: 'api/member/get_notice'
				})
					.then((res) => {
						console.log(res);
						if (res.data.code == 1) {
							let data = res.data.data;
							if (data.length == 0) {
								this.show = true;
							} else {
								this.show = false;
							}
							this.list = data;
						} else {
							this.$tip.tip(res.data.msg);
							this.show = true;
						}
					})
					.catch((err) => {});
			},
			yijian() {
				this.$http({
					url: 'api/member/set_allread_notice'
				})
					.then((res) => {
						if (res.data.code == 1) {
							this.getList();
						} else {
							this.$tip.tip(res.data.msg);
						}
					})
					.catch((err) => {});
			}
		}
	};
</script>

<style>
	.yidu {
		color: #999;
		padding-right: 20rpx;
	}
	.yidu image {
		width: 40rpx;
		height: 40rpx;
		vertical-align: -10%;
		margin-right: 10rpx;
	}
	.box {
		padding: 20rpx;
		box-sizing: border-box;
	}
	.box .list {
		padding: 26rpx 0;
		border-bottom: 1rpx solid #eaeaea;
	}
	.box .yuan {
		display: inline-block;
		width: 26rpx;
		height: 26rpx;
		border-radius: 50%;
		background-color: #fd322c;
		margin-right: 20rpx;
	}
	.box .con {
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		line-height: 1.2;
		color: #999;
		margin-top: 10rpx;
	}
	.box .time {
		color: #999;
	}
</style>
